package com.heima.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.model.behavior.dto.BehaviorDto;
import com.heima.model.behavior.pojos.AdUnLikesBehavior;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.pojos.ApUserFollow;
import com.heima.user.service.IApUserFanService;
import com.heima.user.service.IApUserFollowService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @date 2024/8/21 22:14
 * @Author JinCc
 * @Description TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/user")
@Slf4j
@RequiredArgsConstructor
public class FanAndFollowController {

    private final IApUserFanService userFanService;
    private final IApUserFollowService userFollowService;


    /**
     * 粉丝和关注
     * @param dto
     * @return
     */
    @PostMapping("/user_follow/")
    public ResponseResult collectionBehavior(@RequestBody BehaviorDto dto){
        return userFanService.collectionBehavior(dto);
    }


    /**
     * 查询关注状态
     */
    @RequestMapping ("/follow/")
    public String followArticle(@RequestBody BehaviorDto dto){
        LambdaQueryWrapper<ApUserFollow> wrapper = new LambdaQueryWrapper<>();

        wrapper.eq(!ObjectUtils.isEmpty(dto.getUserId()),ApUserFollow::getUserId,dto.getUserId());
        wrapper.eq(!ObjectUtils.isEmpty(dto.getArticleId()),ApUserFollow::getFollowId,dto.getAuthorId());
        ApUserFollow one = userFollowService.getOne(wrapper);
        return String.valueOf(one.getOperation());

    }
}
